package com.quickcode.example.juc;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created by 张波 on 2019/10/25.
 */
@Slf4j
public class FutureTaskExample1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask = new FutureTask(new Callable() {
            @Override
            public Object call() throws Exception {
                log.info("start call");
                Thread.sleep(5000);
                return "ok";
            }
        });
        new Thread(futureTask).start();
        log.info("main start");
        String result = futureTask.get();
        log.info("result:{}",result);
    }
}
